<!DOCTYPE html>
<html class="ui-page-login">

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title></title>
		<link href="../css/mui.min.css" rel="stylesheet" />
		<style>
			.ui-page-login,
			body {
				width: 100%;
				height: 100%;
				margin: 0px;
				padding: 0px;
			}
			.mui-content{height: 100%;}
			.area {
				margin: 20px auto 0px auto;
			}
			/*
			.mui-input-group {
				margin-top: 10px;
			}
			
			.mui-input-group:first-child {
				margin-top: 20px;
			}
			
			.mui-input-group label {
				width: 32%;
			}
			
			.mui-input-row label~input,
			.mui-input-row label~select,
			.mui-input-row label~textarea {
				width: 68%;
			}
			*/
			.mui-checkbox input[type=checkbox],
			.mui-radio input[type=radio] {
				top: 6px;
			}
			
			.mui-content-padded {
				margin-top: 25px;
			}
			
			.mui-btn {
				padding: 10px;
			}
			
			.link-area {
				display: block;
				margin-top: 25px;
				text-align: center;
			}
			
			.spliter {
				color: #bbb;
				padding: 0px 8px;
			}
			
			.oauth-area {
				position: absolute;
				bottom: 20px;
				left: 0px;
				text-align: center;
				width: 100%;
				padding: 0px;
				margin: 0px;
			}
			
			.oauth-area .oauth-btn {
				display: inline-block;
				width: 50px;
				height: 50px;
				background-size: 30px 30px;
				background-position: center center;
				background-repeat: no-repeat;
				margin: 0px 20px;

				border: solid 1px #ddd;
				border-radius: 25px;
			}
			
			.oauth-area .oauth-btn:active {
				border: solid 1px #aaa;
			}
			
			.oauth-area .oauth-btn.disabled {
				background-color: #ddd;
			}
			
	 .mui-input-group label {width: 26%;padding-top:14px;padding-bottom:14px;text-align:left;}
	 
	 .mui-input-row label~input,
	 .mui-input-row label~select,
	 .mui-input-row label~textarea {width: 74%;}
	 
	 .mui-input-row .mui-input-clear ~ .mui-icon-clear,
	 .mui-input-row .mui-input-password ~ .mui-icon-eye {right: 15px; }
	 .mui-input-row .mui-input-password ~ .mui-icon-eye{font-size: 22px;top: 12px;}
	
	 .mui-input-row label~#VerificationCode{width: 48%;box-sizing: border-box;}
	 .mui-input-row .mui-btn{width: 26%;box-sizing: border-box;right: 15px;padding: 8px 0px;}
	 .mui-btn-outlined {margin-top: 6px;color: #00B4FF;border: 1px solid #00B4FF; }
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<h1 class="mui-title">登录</h1>
		</header>
		<div class="mui-content">
			<form id='login-form' class="mui-input-group">
				<div class="mui-input-row">
					<label>手机号</label>
					<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
				</div>
				
				<div class="mui-input-row">
					<label>验证码</label>
					<button type="button" id="btnVerificationCode" class="mui-btn mui-btn-outlined">获取验证码</button>
                    <input id="VerificationCode" type="text" class="mui-input" placeholder="请输入验证码">
				</div>
			</form>
			<form class="mui-input-group">
				<ul class="mui-table-view mui-table-view-chevron">
					<li class="mui-table-view-cell">
						自动登录
						<div id="autoLogin" class="mui-switch">
							<div class="mui-switch-handle"></div>
						</div>
					</li>
				</ul>
			</form>
			<div class="mui-content-padded">
				<button id='login' class="mui-btn mui-btn-block mui-btn-primary">登录</button>
				<div class="link-area"><a id="reg">申请加盟</a> <span class="spliter">|</span> <a href="tel:15999611930" class="call">客服</a>
				</div>
			</div>
			<div class="mui-content-padded oauth-area">

			</div>
		</div>
		<script src="../js/mui.min.js"></script>
		<script src="../js/vue.min.js"></script>
		<script src="../js/tools.js"></script>
		
		<script>
			
			document.getElementById('reg').addEventListener('tap', function(event)
			{
				mui.openWindow(
				{
			     	url:'workshop/reg.html', 
			     	id:'/html/workshop/reg.html'
			  	});
			});
			
			function waitNextSendMsg()
			{
				document.getElementById('btnVerificationCode').disabled = true;
					var iPointTime = 0;
					debugger;
					var iHand = setInterval(function()
					{
						if(iPointTime <=30)
						{
							document.getElementById("btnVerificationCode").innerText = iPointTime+"";
						}
						else
						{
							document.getElementById('btnVerificationCode').disabled = false;
							document.getElementById('btnVerificationCode').innerText = "获取验证码";
							clearInterval(iHand); 
							iPointTime = 0;
						}
						iPointTime++;
						
					},1000);
			}
			
			document.getElementById('btnVerificationCode').addEventListener('tap', function(event)
			{
				if(document.getElementById('account').value.trim() == "")
				{
					mui.toast("请输入手机号")	
					return;
				}

				genpost('/zdm/AppApi/UserAuth/sendMerRegSms',
				{Mobile:document.getElementById('account').value},
				function(data)
				{
					//alert(data.VerifyCode);
					switch(data.SendOk)
					{
						case 0:
							mui.toast('发送失败');
							waitNextSendMsg();
							break;
						case 1:
							mui.toast('发送成功');
							//document.getElementById('VerificationCode').value = data.VerifyCode;
							waitNextSendMsg();
							break;
						case 2:
							mui.toast('普通用户无法登录');
							break;
						case 3:
							mui.toast('审核中或停业整顿');
							break;
							
						case 4:
							mui.toast('非餐饮企业用户');
							break;
							
						case 5:
							mui.toast('无此用户');
							break;	
						
						case 6:
							mui.toast('停业整顿');
							break;	
							
						case 7:
							mui.toast('未通过审核:'+data.RejectDesc+',请重新申请注册');
							break;
							
						case 8:
							mui.toast('店铺下无操作员，请联系管理员');
							break;
					}
				
				});
			});
			
			var loginButton = document.getElementById('login');

			loginButton.addEventListener('tap', function(event) 
			{
				if(document.getElementById('account').value.trim() == "")
				{
					mui.toast("请输入手机号")	
					return;
				}
				
				if(document.getElementById('VerificationCode').value.trim() == "")
				{
					mui.toast("请输入验证码")	
					return;
				}
				
				genpost('/zdm/AppApi/UserAuth/newLogin',
				{
					Mobile:document.getElementById('account').value,
					VerifyCode:document.getElementById('VerificationCode').value,
					ClientId:plus.push.getClientInfo().clientid
				},
				function(data)
				{
					//alert(data.VerifyStat);
					if(data.VerifyStat == 1 || data.VerifyStat == 4)
					{
						g_jsonData.putData("SesId",data.SesId);
						g_jsonData.putData("UserId",data.UserId);
						
						setTimeout(function()
						{ 
							mui.toast('登录成功');
							if(mui.os.plus)
							{
								mui.back();
							}
							else
							{//debugger;
								window.location.href = g_jsonData.getData("lastUrl");
							}						
						}, 500);
					}
					else
					{
						mui.toast('登录失败');
					}
				});
			});
			
			
			
			
			
			
			(function($, doc) 
			{
				$.init({
					statusBarBackground: '#f7f7f7'
				});
				
				
//				$.plusReady(function() {
//				
//				//$.enterfocus('#login-form input', function() {
//				//	$.trigger(loginButton, 'tap');
//				//});
//				
//					window.addEventListener('resize', function() {
//						oauthArea.style.display = document.body.clientHeight > 400 ? 'block' : 'none';
//					}, false);
//					//
//					var backButtonPress = 0;
//					$.back = function(event) {
//						backButtonPress++;
//						if (backButtonPress > 1) {
//							plus.runtime.quit();
//						} else {
//							plus.nativeUI.toast('再按一次退出应用');
//						}
//						setTimeout(function() {
//							backButtonPress = 0;
//						}, 1000);
//						return false;
//					};
//				});
			}(mui, document));
		</script>
	</body>

</html>